//
//  GJokeVC.m
//  guess
//
//  Created by fank on 15/11/4.
//  Copyright © 2015年 fank. All rights reserved.
//

#import "GJokeVC.h"
#import "GHttpEnqine.h"
#import "HYSegmentedControl.h"
#import "JT3DScrollView.h"
#import "GJokeView.h"
#import "GFunView.h"


@interface GJokeVC ()<UIScrollViewDelegate>
@property (strong, nonatomic)HYSegmentedControl *segmentedControl;
@property (weak, nonatomic) IBOutlet JT3DScrollView *changeScrolView;
@end

@implementation GJokeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self createScrolView];
    [self createNaviBar];
}


-(void)createScrolView
{
    //效果
    self.changeScrolView.effect =JT3DScrollViewEffectCarousel;
    self.changeScrolView.delegate = self;
    self.changeScrolView.userInteractionEnabled = YES;
    [self createJokeText];
    [self createJokeImage];
    [self createFunView];
}


-(void)createNaviBar
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, G_WIDTH, 44)];
    titleView.userInteractionEnabled = YES;
    titleView.backgroundColor = UIColorFromRGBValue(0xf3f3f3);
    self.segmentedControl = [[HYSegmentedControl alloc] initWithOriginY:20 Titles:@[@"文字笑话", @"图片笑话", @"有意思"] delegate:self];
    [titleView addSubview:_segmentedControl];
    [self.view addSubview:titleView];
    
    //背景颜色 UIColorFromRGBValue(0xDBE0E4)
    self.view.backgroundColor = UIColorFromRGBValue(0xDBE0E4);
}


//hySegmentedControlSelect  delegate
- (void)hySegmentedControlSelectAtIndex:(NSInteger)index
{
    NSLog(@"%ld",(long)index);
    
    [self.changeScrolView loadPageIndex:index animated:YES];
    
}

//Card delegate
- (void)createJokeText
{

    CGFloat x = self.changeScrolView.subviews.count *  (G_WIDTH-20);
   GJokeView * view = [[GJokeView alloc] initWithFrame:CGRectMake(x, 0, G_WIDTH-20, G_HEIGHT-118) withJokeTyoe:JokeText];
    view.GjokeVC = self;
    view.userInteractionEnabled = YES;
//UIColorFromRGBValue(0xf0ffff)
    view.backgroundColor = [UIColor greenColor];
    
    view.layer.cornerRadius = 8.;
    
    [self.changeScrolView addSubview:view];
    self.changeScrolView.contentSize = CGSizeMake(x + G_WIDTH-20, G_HEIGHT-118);
}



- (void)createJokeImage
{
    
    CGFloat x = self.changeScrolView.subviews.count *  (G_WIDTH-20);
    GJokeView * view = [[GJokeView alloc] initWithFrame:CGRectMake(x, 0, G_WIDTH-20, G_HEIGHT-118) withJokeTyoe:JokeImage];
    view.userInteractionEnabled = YES;
    view.selfVC =self;
    view.GjokeVC = self;
    //UIColorFromRGBValue(0xf0ffff)
    view.backgroundColor = UIColorFromRGBValue(0xDBE0E4);
    
    view.layer.cornerRadius = 8.;
    
    [self.changeScrolView addSubview:view];
    self.changeScrolView.contentSize = CGSizeMake(x + G_WIDTH-20, G_HEIGHT-118);
}



-(void)createFunView
{
    CGFloat x = self.changeScrolView.subviews.count *  (G_WIDTH-20);
    GFunView  * view = [[GFunView alloc] initWithFrame:CGRectMake(x, 0, G_WIDTH-20, G_HEIGHT-118)];
    view.userInteractionEnabled = YES;
    view.selfVC =self;
    view.backgroundColor = UIColorFromRGBValue(0xDBE0E4);
    view.layer.cornerRadius = 8.;
    [self.changeScrolView addSubview:view];
    self.changeScrolView.contentSize = CGSizeMake(x + G_WIDTH-20, G_HEIGHT-118);
}


#pragma  mark - srollView delegate
//scrollView delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"%ld",self.changeScrolView.currentPage);
    [self.segmentedControl changeSegmentedControlWithIndex:self.changeScrolView.currentPage];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


+(CGFloat)heightWithImage:(UIImage *)img
{
    return img.size.height;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
